package com.zhouyu.exampleThread.proAndComsu;

import lombok.Data;
import lombok.extern.log4j.Log4j2;

/**
 * @Description:水果消费者
 */
@Data
@Log4j2
public class FruitConsumer {
  private FruitFactory fruitFactory;
  private ConsumerLock consumerLock;
  private ProductorLock productorLock;

  public void consu(){
    if(!fruitFactory.isfull()){
        synchronized (consumerLock){
          if(!fruitFactory.isfull()){
            try {
              consumerLock.wait();
            } catch (InterruptedException e) {
              e.printStackTrace();
              throw new RuntimeException("消费者暂停异常");
            }
          }
        }
        synchronized (productorLock){
            while (!fruitFactory.isfull()){
              log.info("唤醒生产者");
              productorLock.notify();
            }
        }
    }else {
      fruitFactory.remove();
    }
  }

}
